#ifndef OMMIT_UNIT_TEST
#include <UnitTest++/src/UnitTest++.h>
#endif

#include <string>
#include <fstream>
#include <iostream>
#include <boost/filesystem.hpp>

#include "GenNames.h"
#include "GenInfo.h"
#include "GenerateGraph.h"
#include "WriteMemoryToFile.hpp"


int main(int argc, char** argv)
  {
#ifndef OMMIT_UNIT_TEST
  UnitTest::RunAllTests();
#endif

  std::string path = argv[1];
  std::string config_file = argv[2];
  GenInfoMap to_generate;

  //-- Reading config file ------------------------------------------------
  std::ifstream if_config_file(config_file.c_str());
  if_config_file >> to_generate;
  if_config_file.close();
  //-----------------------------------------------------------------------

  std::string folder_name;
  std::string file_name;
  
  boost::filesystem::create_directory(path);
  
  std::cout << "Generating started.\n";
  std::cout << "-----------------------------------------------------------\n";

  for(GenInfoMap::const_iterator iter = to_generate.begin(); iter!=to_generate.end(); ++iter)
    {
    size_t edges = iter->first.m_edges;
    size_t filling = iter->first.m_filling;
    size_t max = iter->first.m_max;
    size_t count = iter->second;
    
    std::cout << "Graph parameters:   edges   = " << edges << '\n'
              << "                    filling = " << filling << "%\n"
              << "                    max     = " << max << '\n'
              << "                    count   = " << count << '\n';
    std::cout << "Progress :  00%";
    folder_name = GenFolderName(edges, filling, max);
    boost::filesystem::create_directory(path+'\\'+folder_name);

    float *p = new float[edges*edges];
    
    for(size_t i = 0; i<count; ++i)
      {
      GenerateGraph(p, edges, filling, max);
      WriteMemoryToFile(p, edges, path+'\\'+folder_name+'\\'+GenFileName(i));
      std::cout << "\b\b\b";
      if (100*(i+1)/count < 10)
        std::cout << 0;
      std::cout << 100*(i+1)/count << '%';
      }
    delete[] p;
    std::cout << "\n-----------------------------------------------------------\n";
    }

  return 0;
  }